package com.example.demo.controller;


import com.example.demo.entity.Team;
import com.example.demo.service.TeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/teams")
public class TeamController {

    @Autowired
    private TeamService teamService;

    // 获取所有球队
    @GetMapping
    public List<Team> getAllTeams() {
        return teamService.getAllTeams();
    }

    // 根据ID获取球队
    @GetMapping("/{id}")
    public Team getTeamById(@PathVariable Long id) {
        return teamService.getTeamById(id).orElse(null);
    }

    // 新增或更新球队
    @PostMapping
    public Team createOrUpdateTeam(@RequestBody Team team) {
        return teamService.saveTeam(team);
    }

    // 删除球队
    @DeleteMapping("/{id}")
    public void deleteTeam(@PathVariable Long id) {
        teamService.deleteTeamById(id);
    }
}